/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aic.client;

import aic.beans.Customer;
import aic.beans.Item;
import aic.lists.AvailableItemsList;
import aic.lists.CustomerList;
import aic.misc.DebugPrint;
import aic.ws.OrderManagementService;
import aic.ws.SMSService;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;

public final class Client {

//    private static final QName SERVICE_NAME = new QName("http://infosys.tuwien.ac.at/ait09/ass1/dto/notification", "NotificationService");
//    private static final QName PORT_NAME = new QName("http://infosys.tuwien.ac.at/ait09/ass1/dto/notification", "NotificationPT");

//    private static final URL WSDL_URL = new URL("http://localhost:9000/SMSService?wsdl");

    public Client() {
        System.out.println("Creating Client:");
        try {
//            URL WSDL_URL = new URL("http://localhost:9000/SMSService?wsdl");

            
            Service smsService = Service.create(new URL("http://localhost:8088/SMSService?wsdl"), new QName("http://infosys.tuwien.ac.at/ait09/ass1/dto/notification", "NotificationService"));

            // Endpoint Address
//            String endpointAddress = "http://localhost:9000/SMSService";

            // Add a port to the Service
            smsService.addPort(new QName("http://infosys.tuwien.ac.at/ait09/ass1/dto/notification", "NotificationPT"), SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:8088/SMSService");
            SMSService hw = smsService.getPort(SMSService.class);
            
            DebugPrint.println("SMSService created successfully");

            Customer cust = new Customer();
            cust.setName("lui");
            CustomerList.add(cust);
            DebugPrint.println("Customer created successfully");

            DebugPrint.println("Notifying customer worked: " + hw.notify_customer(cust, "Mes"));


            // OrderManagementService

            Service orderManagementService = Service.create(new URL("http://localhost:8083/OrderManagementService?wsdl"), new QName("http://infosys.tuwien.ac.at/ait09/ass1/dto/orderManagement", "OrderManagementService"));
            orderManagementService.addPort(new QName("http://infosys.tuwien.ac.at/ait09/ass1/dto/orderManagement", "OrderManagementPT"), SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:8083/OrderManagementService");
            OrderManagementService oms = orderManagementService.getPort(OrderManagementService.class);

            DebugPrint.println("OrderManagementService created successfully");

            oms.insert_test_data();

            AvailableItemsList.printList();

            oms.check_availability(new Item(12, "Fountain-Pen", 14.90));

        } catch (MalformedURLException ex) {
            Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
        }
        DebugPrint.println("Client created successfully");
    }

}
